package com.tfblog.blog.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.tfblog.blog.entity.Tag;
import com.tfblog.blog.entity.Type;
import com.tfblog.blog.mapper.TagMapper;
import com.tfblog.blog.service.TagService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author tfeng
 * @since 2021-04-26
 */
@Service
public class TagServiceImpl extends ServiceImpl<TagMapper, Tag> implements TagService {

    @Autowired
    private TagMapper tagMapper;

    @Override
    public List<Tag> findTags() {
        //查询所有的标签
        return tagMapper.selectList(null);
    }


    @Override
    public Tag findTagByName(String name) {
        QueryWrapper<Tag> wrapper = new QueryWrapper<>();
        wrapper.eq("name",name);
        return tagMapper.selectOne(wrapper);
    }


    @Override
    public Tag findTagById(Long id) {
        return tagMapper.selectById(id);
    }


    @Transactional
    @Override
    public void deleteById(Long id) {
        tagMapper.deleteById(id);

    }
}
